package org.nlp2rdf.navigator.benchmark;

import com.hp.hpl.jena.rdf.model.Resource;
import org.aksw.commons.semweb.sparql.core.CachingSparqlEndpoint;
import org.aksw.commons.semweb.sparql.core.HttpSparqlEndpoint;
import org.aksw.commons.semweb.sparql.core.ISparqlEndpoint;
import org.aksw.commons.util.collections.StringTransformer;
import org.dllearner.core.EvaluatedDescription;
import org.nlp2rdf.navigator.refactored.IClassifier;
import org.nlp2rdf.navigator.component.learn.ILearn;
import org.nlp2rdf.navigator.refactored.SparqlService;
import org.springframework.context.ApplicationContext;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 22, 2010
 * Time: 7:10:28 PM
 */
public class BenchmarkContext
{
    private ISparqlEndpoint sparqlEndpoint;
    private Set<String> graphNames;
    private IGenericLearner<Resource, EvaluatedDescription>  learner;
    private IGenericClassifier<Resource, EvaluatedDescription> classifier;

    public BenchmarkContext(ISparqlEndpoint sparqlEndpoint, Set<String> graphNames, IGenericLearner<Resource, EvaluatedDescription>  learner, IGenericClassifier<Resource, EvaluatedDescription> classifier)
    {
        this.sparqlEndpoint = sparqlEndpoint;
        this.graphNames = graphNames;
        this.learner = learner;
        this.classifier = classifier;
    }

    public BenchmarkContext(ApplicationContext context)
    {
        SparqlService sparqlService = (SparqlService)context.getBean("dbpedia.sparqlservice");

        String serviceUrl = sparqlService.getSparqlEndpointURL();
        graphNames = new HashSet<String>(sparqlService.getDefaultGraph());

        HttpSparqlEndpoint coreSparqlEndpoint = new HttpSparqlEndpoint(serviceUrl, graphNames);
        sparqlEndpoint = new CachingSparqlEndpoint(coreSparqlEndpoint, "/tmp/sparqlCache");
        //graphNames = Collections.singleton("http://dbpedia.org");

        ILearn learnerBean = (ILearn)context.getBean("dbpedia.learn");
        IClassifier classifierBean = (IClassifier)context.getBean("dbpedia.classifier");

        NkeGenericLearner learnerCore = new NkeGenericLearner(learnerBean);
        NkeGenericClassifier classifierCore = new NkeGenericClassifier(classifierBean);

        learner = new WrapperGenericLearner<Resource, String, EvaluatedDescription>(learnerCore, new StringTransformer<Resource>());
        classifier = new WrapperGenericClassifier<Resource, String, EvaluatedDescription>(classifierCore, new StringToResourceTransformer());
    }

    public ISparqlEndpoint getSparqlEndpoint() {
        return sparqlEndpoint;
    }

    public Set<String> getGraphNames() {
        return graphNames;
    }

    public IGenericLearner<Resource, EvaluatedDescription> getLearner() {
        return learner;
    }

    public IGenericClassifier<Resource, EvaluatedDescription> getClassifier() {
        return classifier;
    }
}
